#########################################
#         File name   :install-opencv.sh
#         Author      :kangkangliang
#         File desc   :
#         Mail        :liangkangkang@paag.com
#         Create time :2016-07-28
#########################################
#!/usr/bin/bash

arch=$(uname -m)
if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
flag=1
else
flag=0
fi
echo "Installing OpenCV 2.4.13"
mkdir OpenCV
cd OpenCV
echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get -y remove ffmpeg x264 libx264-dev
echo "Installing Dependenices"
sudo apt-get -y install libopencv-dev
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install libtbb-dev libeigen3-dev
sudo apt-get -y install libqt4-dev libgtk2.0-dev
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
sudo apt-get -y install x264 v4l-utils ffmpeg
sudo apt-get -y install libgtk2.0-dev
echo "Downloading OpenCV 2.4.13"
if ! [ -f "OpenCV-2.4.13.zip" ]; then
  wget -O OpenCV-2.4.13.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.13/opencv-2.4.13.zip/download
fi
echo "Installing OpenCV 2.4.13"
if ! [ -d "opencv-2.4.13" ]; then
  unzip OpenCV-2.4.10.zip
fi
#rm OpenCV-2.4.10.zip
cd opencv-2.4.13
rm -rf build
mkdir build
cd build
cmake -D CUDA_ARCH_BIN=3.2 -D CUDA_ARCH_PTX=3.2 -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D BUILD_TIFF=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j 2
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

##include <stdio.h>
##include <opencv2/opencv.hpp>
#
#using namespace cv;
#
#int main(int argc, char** argv )
#{
#    if ( argc != 2 )
#    {
#        printf("usage: DisplayImage.out <Image_Path>\n");
#        return -1;
#    }
#
#    Mat image;
#    image = imread( argv[1], 1 );
#
#    if ( !image.data )
#    {
#        printf("No image data \n");
#        return -1;
#    }
#    namedWindow("Display Image", WINDOW_AUTOSIZE );
#    imshow("Display Image", image);
#
#    waitKey(0);
#
#    return 0;
#}
#
#CMakeLists.txt
#cmake_minimum_required(VERSION 2.8)
#project( ShowImage )
#find_package( OpenCV REQUIRED )
#add_executable( ShowImage ShowImage.cpp )
#target_link_libraries( ShowImage ${OpenCV_LIBS} )
#
